package work.xiaohong.gupiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.dao.BaijiuMapper;
import work.xiaohong.gupiao.pojo.Baijiu;
import work.xiaohong.gupiao.service.BaijiuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BaijiuServiceImpl implements BaijiuService {

    @Autowired
    private BaijiuMapper baijiuMapper;


    /**
     * 条件+分页查询Baijiu
     * @param baijiu 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Baijiu> findPage(Baijiu baijiu, int page, int size){
        // 构建查询条件
        QueryWrapper<Baijiu> queryWrapper = new QueryWrapper<Baijiu>(baijiu);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return baijiuMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Baijiu
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Baijiu> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return baijiuMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Baijiu
     * @param baijiu
     * @return
     */
    @Override
    public List<Baijiu> findList(Baijiu baijiu){
        // 构建查询条件
        QueryWrapper<Baijiu> queryWrapper = new QueryWrapper<Baijiu>(baijiu);
        // 查询数据
        return baijiuMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Baijiu
     * @param id
     */
    @Override
    public void delete(Integer id){
        baijiuMapper.deleteById(id);
    }

    /**
     * 根据ID修改Baijiu
     * @param baijiu
     */
    @Override
    public void update(Baijiu baijiu){
        baijiuMapper.updateById(baijiu);
    }

    /**
     * 增加Baijiu
     * @param baijiu
     */
    @Override
    public void add(Baijiu baijiu){
        baijiuMapper.insert(baijiu);
    }

    /**
     * 根据ID查询Baijiu
     * @param id
     * @return
     */
    @Override
    public Baijiu findById(Integer id){
        return  baijiuMapper.selectById(id);
    }

    /**
     * 查询全部Baijiu数据
     * @return
     */
    @Override
    public List<Baijiu> findAll() {
        return baijiuMapper.selectList(null);
    }
}
